﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ConstructorTestExtension", Namespace="http://kis.x-road.eu/", Target=typeof(ConstructorTestExtension))]
    public class ConstructorTestExtensionSerializer : global::Kis.Xroad.Eu.XsdMinOccursMaxOccursComplexTypesSerializer {
        
        public ConstructorTestExtensionSerializer(ConstructorTestExtension clazz) : 
                base(clazz) {
        }
        
        protected new ConstructorTestExtension clazz {
            get {
                return ((ConstructorTestExtension)(base.clazz));
            }
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.CT2Prop!=null) {
                Writer.WriteStartElement("CT2Prop");
                Writer.WriteString(clazz.CT2Prop.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.CT2Prop1!=null) {
                Writer.WriteStartElement("CT2Prop1");
                Writer.WriteString(clazz.CT2Prop1.ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("CT2Prop2");
            if (clazz.CT2Prop2!=null) {
                Writer.WriteString(clazz.CT2Prop2.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : CT2Prop2");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("CT2Prop3");
            if (clazz.CT2Prop3!=null) {
                Writer.WriteString(clazz.CT2Prop3.ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="CT2Prop") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ConstructorTestExtension>CT2Prop");
                }
                clazz.CT2Prop = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("CT2Prop"));
            }
            if (Reader.LocalName=="CT2Prop1") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.CT2Prop1 = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("CT2Prop1"));
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="CT2Prop2") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ConstructorTestExtension>CT2Prop2");
                }
                clazz.CT2Prop2 = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("CT2Prop2"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ConstructorTestExtension>CT2Prop2", Reader.LocalName);
            }
            if (Reader.LocalName=="CT2Prop3") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.CT2Prop3 = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("CT2Prop3"));
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ConstructorTestExtension>CT2Prop3", Reader.LocalName);
            }
        }
    }
}
